package top.loveyumin1314.music.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import top.loveyumin1314.music.bean.BaseBean;
import top.loveyumin1314.music.bean.UserActionBean;

import java.io.IOException;

/**
 * author Kerry
 * date 2017/10/10
 * desp null
 */

public class JacksonUtil {

    private static ObjectMapper mapper = new ObjectMapper();

    public static UserActionBean data2ActionBean(String data) throws IOException {
        return mapper.readValue(data, UserActionBean.class);
    }

    public static String actionBean2Data(Object actionBean) throws JsonProcessingException {
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return mapper.writeValueAsString(actionBean);
    }

}
